package cn.yuanqiao.archive.supervision.service.impl;

import cn.yuanqiao.archive.appManager.domain.DataScopeBase;
import cn.yuanqiao.archive.supervision.domain.Supervision;
import cn.yuanqiao.archive.supervision.domain.SupervisionDa;
import cn.yuanqiao.archive.supervision.mapper.SupervisionDaMapper;
import cn.yuanqiao.archive.supervision.mapper.SupervisionMapper;
import cn.yuanqiao.archive.supervision.service.ISupervisionService;
import cn.yuanqiao.common.utils.DateUtils;
import cn.yuanqiao.common.utils.StringUtils;
import cn.yuanqiao.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 督察指导主表Service业务层处理
 * 
 * @author xy
 * @date 2023-08-01
 */
@Service
public class SupervisionServiceImpl implements ISupervisionService
{
    @Autowired
    private SupervisionMapper supervisionMapper;

    @Autowired
    private SupervisionDaMapper supervisionDaMapper;

    /**
     * 查询督察指导主表
     * 
     * @param id 督察指导主表主键
     * @return 督察指导主表
     */
    @Override
    public Supervision selectSupervisionById(Long id)
    {
        return supervisionMapper.selectSupervisionById(id,new Supervision().getTableName());
    }

    /**
     * 查询督察指导主表列表
     * 
     * @param supervision 督察指导主表
     * @return 督察指导主表
     */
    @Override
    public List<Supervision> selectSupervisionList(Supervision supervision)
    {
        return supervisionMapper.selectSupervisionList(new DataScopeBase(),supervision);
    }

    /**
     * 新增督察指导主表
     * 
     * @param supervision 督察指导主表
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertSupervision(Supervision supervision)
    {
        supervision.setCreateId(SecurityUtils.getUserId());
        supervision.setCreateTime(DateUtils.getNowDate());
        supervision.setState("0");
        //修改
        if(!StringUtils.isEmpty(supervision.getDaIds())) {
            supervisionDaMapper.updateBySupervisionId(new SupervisionDa().getTableName(), supervision.getId(), supervision.getDaIds());
        }
        return supervisionMapper.insertSupervision(supervision);
    }

    /**
     * 修改督察指导主表
     * 
     * @param supervision 督察指导主表
     * @return 结果
     */
    @Override
    public int updateSupervision(Supervision supervision)
    {
        return supervisionMapper.updateSupervision(supervision);
    }

    /**
     * 批量删除督察指导主表
     * 
     * @param ids 需要删除的督察指导主表主键
     * @return 结果
     */
    @Override
    public int deleteSupervisionByIds(Long[] ids)
    {
        return supervisionMapper.deleteSupervisionByIds(ids);
    }

    /**
     * 删除督察指导主表信息
     * 
     * @param id 督察指导主表主键
     * @return 结果
     */
    @Override
    public int deleteSupervisionById(Long id)
    {
        return supervisionMapper.deleteSupervisionById(id);
    }
}
